package com.kitom.spring.boot.starter.qq.config;

import com.kitom.qqmap.api.QQmapService;
import com.kitom.qqmap.api.impl.QQmapServiceImpl;
import com.kitom.qqmap.config.QQmapConfig;
import com.kitom.spring.boot.starter.qq.properties.QQMapProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置.
 * @author <a href="https://gitee.com/kitom">ki_tom</a>
 * @since 2019-12-26
 */
@Configuration
@ConditionalOnClass(QQmapService.class)
@EnableConfigurationProperties(QQMapProperties.class)
@ConditionalOnProperty(prefix = "lbs.map.tencent", name = "enabled", matchIfMissing = true)
public class QQMapAutoConfiguration {

    private final QQMapProperties properties;

    public QQMapAutoConfiguration(QQMapProperties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean(QQmapService.class)
    public QQmapService baiduMapService() {
        QQmapConfig config = new QQmapConfig();
        config.setKey(properties.getKey());
        final QQmapService service = new QQmapServiceImpl();
        service.setQQmapConfig(config);
        return service;
    }
}
